#include "config.h"
#include "globals.h"
#include "INIReader.h"

void Config::load_config(std::string iniFile)
{
    output.write("Loading config file: %s", iniFile.c_str());
    INIReader cfg(iniFile);

    SCREEN_WIDTH = cfg.GetInteger("video", "screen_width", 640);
    SCREEN_HEIGHT = cfg.GetInteger("video", "screen_height", 480);
    SCREEN_BPP = cfg.GetInteger("video", "screen_bpp", 32);
    SCREEN_FULLSCREEN = cfg.GetInteger("video", "screen_fullscreen", 0);
    FRAMES_PER_SECOND = cfg.GetInteger("video", "frames_per_second", 60);
    ENABLE_FPS_CAP = cfg.GetInteger("video", "enable_fps_cap", 1);

    AUDIO_FREQUENCY = cfg.GetInteger("audio", "audio_frequency", 44100);
    AUDIO_CHANNELS = cfg.GetInteger("audio", "audio_channels", 2);
    AUDIO_CHUNKSIZE = cfg.GetInteger("audio", "audio_chunksize", 1024);

    MAP_WIDTH = cfg.GetInteger("map", "map_width", 1280);
    MAP_HEIGHT = cfg.GetInteger("map", "map_height", 960);

    MINIMAP_WIDTH = cfg.GetInteger("hud", "minimap_width", 256);
    MINIMAP_HEIGHT = cfg.GetInteger("hud", "minimap_height", 192);

    SERVER_IP = cfg.Get("network", "server_ip", "miemala.com");
    SERVER_PORT = cfg.GetInteger("network", "server_port", 1337);
    USERNAME = cfg.Get("network", "username", "Unnamed");
}

int Config::get_screen_width()
{
    return SCREEN_WIDTH;
}

int Config::get_screen_height()
{
    return SCREEN_HEIGHT;
}

int Config::get_screen_bpp()
{
    return SCREEN_BPP;
}

int Config::get_screen_fullscreen()
{
    return SCREEN_FULLSCREEN;
}

int Config::get_frames_per_second()
{
    return FRAMES_PER_SECOND;
}

int Config::get_enable_fps_cap()
{
    return ENABLE_FPS_CAP;
}

int Config::get_audio_frequency()
{
    return AUDIO_FREQUENCY;
}

int Config::get_audio_channels()
{
    return AUDIO_CHANNELS;
}

int Config::get_audio_chunksize()
{
    return AUDIO_CHUNKSIZE;
}

int Config::get_map_width()
{
    return MAP_WIDTH;
}

int Config::get_map_height()
{
    return MAP_HEIGHT;
}

int Config::get_minimap_width()
{
    return MINIMAP_WIDTH;
}

int Config::get_minimap_height()
{
    return MINIMAP_HEIGHT;
}

std::string Config::get_server_ip()
{
    return SERVER_IP;
}

int Config::get_server_port()
{
    return SERVER_PORT;
}

std::string Config::get_username()
{
    return USERNAME;
}
